package com.dtm.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;

import com.dtm.R;

public class ChangeInfo extends Activity {
	private String name;
	private int avatar;
	private Button btnSave;
	private EditText txtNameChange;
//	private ImageButton ibtnChoice[];
	private ImageButton ibtnChoice1;
	private ImageButton ibtnChoice2;
	private ImageButton ibtnChoice3;
	private ImageButton ibtnChoice4;
	private ImageButton ibtnChoice5;
	private ImageButton ibtnChoice6;
	private ImageButton ibtnChoice7;
	private ImageButton ibtnChoice8;
	public final int avt[] = {R.drawable.a0, R.drawable.a1, R.drawable.a2, R.drawable.a3, R.drawable.a4,
			R.drawable.a5, R.drawable.a6, R.drawable.a7, R.drawable.a8};
	
//	public final int idBtn[] = {0,R.id.ibtn_choice_1, R.id.ibtn_choice_2, R.id.ibtn_choice_3, R.id.ibtn_choice_4, 
//			R.id.ibtn_choice_5, R.id.ibtn_choice_6, R.id.ibtn_choice_7, R.id.ibtn_choice_8};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_change_info);
		avatar = avt[0];
		btnSave = (Button) findViewById(R.id.btn_save);
		btnSave.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				txtNameChange = (EditText) findViewById(R.id.txt_Name_Change);
				name = txtNameChange.getText().toString();
				Intent intent = getIntent();
				intent.putExtra("name", name);
				intent.putExtra("avatar", avatar);
				setResult(MainActivity.RESULT_CODE_SAVE, intent);
				finish();
			}
		});
		setButton();
	}	
	
	
private void setButton() {
	ibtnChoice1 = (ImageButton) findViewById(R.id.ibtn_choice_1);
	ibtnChoice1.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			avatar = 1;
		}
	});
	ibtnChoice2 = (ImageButton) findViewById(R.id.ibtn_choice_2);
	ibtnChoice2.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			avatar = 2;
		}
	});	
	ibtnChoice3 = (ImageButton) findViewById(R.id.ibtn_choice_3);
	ibtnChoice3.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			avatar = 3;
		}
	});
	ibtnChoice4 = (ImageButton) findViewById(R.id.ibtn_choice_4);
	ibtnChoice4.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			avatar = 4;
		}
	});
	ibtnChoice5 = (ImageButton) findViewById(R.id.ibtn_choice_5);
	ibtnChoice5.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			avatar = 5;
		}
	});
	ibtnChoice6 = (ImageButton) findViewById(R.id.ibtn_choice_6);
	ibtnChoice6.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			avatar = 6;
		}
	});
	ibtnChoice7 = (ImageButton) findViewById(R.id.ibtn_choice_7);
	ibtnChoice7.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			avatar = 7;
		}
	});
	ibtnChoice8 = (ImageButton) findViewById(R.id.ibtn_choice_8);
	ibtnChoice8.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			avatar = 8;
		}
	});
}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.change_info, menu);
		return true;
	}

}
